<template>
	<view>
		<u-sticky>
			<view class="head">
				<block v-if="update">
					<view class="u-font-xl t-white">修改信息</view>
				</block>
				<block v-else>
					<block v-if="userType ==1">
						<view class="u-font-xl t-white">企业商户认证</view>
					</block>
					<block v-else-if="userType ==2">
						<view class="u-font-xl t-white">个体工商户认证</view>
					</block>
					<block v-else-if="userType ==3">
						<view class="u-font-xl t-white">个人(服务员)</view>
					</block>
				</block>

				<view class="u-font-sm t-white u-m-t-6">请如实填写，在使用过程中发现以后虚假信息平台不予通过</view>
			</view>
		</u-sticky>

		<!-- 企业商户 -->
		<view v-show="userType==1">
			<u-form :error-type="errorType" labelWidth="auto" :model="form1" ref="form1El" inputAlign="right"
				:label-style="labelStyle">
				<view class="u-m-t-12 u-m-b-12 bg-white u-p-l-24 u-p-r-24">
					<u-form-item label="真实姓名(法人)" prop="fullName">
						<u-input placeholder="请填写真实姓名" v-model="form1.fullName"></u-input>
					</u-form-item>
					<u-form-item label="手机号(法人)" prop="phone">
						<u-input type="number" placeholder="请输入手机号" v-model="form1.phone"></u-input>
					</u-form-item>

					<u-form-item label="提现方式" prop="cashType" v-show="false">
						<template #right>
							<u-button class="u-m-l-12" @click="form1.cashType = item.value"
								:type="item.value==form1.cashType?'success':'default'" size="mini"
								v-for="(item,index) in cashList" :key="index">{{item.name}}</u-button>
						</template>
					</u-form-item>
					<u-form-item label="企业名称" prop="businessName">
						<u-input v-model="form1.businessName" placeholder="请输入企业名称"></u-input>
					</u-form-item>
					<!-- <u-form-item label="公司名称" prop="bank.cardName">
						<u-input v-model="form1.bank.cardName" placeholder="请输入公司名称"></u-input>
					</u-form-item> -->
					<u-form-item label="企业联系人姓名" prop="linkName">
						<u-input v-model="form1.linkName" placeholder="请输入企业联系人姓名"></u-input>
					</u-form-item>

					<u-form-item label="企业联系人电话" prop="linkPhone">
						<u-input type="number" v-model="form1.linkPhone" placeholder="请输入企业联系人电话"></u-input>
					</u-form-item>
					<!-- <u-form-item label="银行卡类型" prop="bank.cardType">
						<template #right>
							<u-button class="u-m-l-12" @click="form1.bank.cardType = item.value"
								:type="item.value==form1.bank.cardType?'success':'default'" size="mini"
								v-for="(item,index) in cardTypeList" :key="index">{{item.name}}</u-button>
						</template>
					</u-form-item> -->
					<u-form-item label="身份证号(法人)" prop="idCard">
						<u-input type="idcard" v-model="form1.idCard" placeholder="请输入身份证号"></u-input>
					</u-form-item>

					<!-- <u-form-item label="银行" prop="bank.bankName">
						<u-input type="select" @click="showBank = true" v-model="form1.bank.bankName"
							placeholder="请选择银行"></u-input>
					</u-form-item> -->
					<!-- <u-form-item label="银行支行" prop="bank.branchName">
						<u-input type="select" @click="showBRcanch = true" v-model="form1.bank.branchName"
							placeholder="请选择支行"></u-input>
					</u-form-item> -->

					<!-- <u-form-item label="银行卡号" prop="bank.cardNo">
						<u-input v-model="form1.bank.cardNo" placeholder="请输入银行卡号"></u-input>
					</u-form-item> -->

				</view>

				<view class="u-m-t-12 u-m-b-12 bg-white u-p-l-24 u-p-r-24">
					<u-form-item class="uploadItem" :border-bottom="false" label-position="top" label="企业营业执照"
						prop="businessLicense">
						<u-upload index="businessLicense" :file-list="busineFileList" ref="businessLicenseEL" :custom-btn="true"
							:auto-upload="false" :max-count='1' @on-list-change="onSuccess">
							<template #addBtn>
								<image mode="widthFix" class="addImg" src="@/static/images/my/busname.png"></image>
							</template>
						</u-upload>
					</u-form-item>

					<u-row gutter="16">
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="身份证正面(法人)" prop="idCardFront">
								<u-upload index="idCardFront" :file-list="idCardFrontFileList" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image mode="widthFix" class="addImg" src="@/static/images/my/idCardFace.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="身份证反面(法人)" prop="idCardBack">
								<u-upload index="idCardBack" :file-list="idCardBackFileList" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image mode="widthFix" class="addImg" src="@/static/images/my/idCardBack.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
					</u-row>

					<!-- <u-row gutter="16" v-show="form1.bank.cardType==2">
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="银行卡正面"
								prop="bank.bankCardFront">
								<u-upload index="bankCardFront" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image style="opacity: .4;" mode="widthFix" class="addImg"
											src="@/static/images/my/bankface.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="银行卡背面" prop="bank.bankCardBack">
								<u-upload index="bankCardBack" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image style="opacity: .4;" mode="widthFix" class="addImg"
											src="@/static/images/my/banback.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
					</u-row> -->

				</view>
			</u-form>
		</view>

		<!-- 个体工商户 -->
		<view v-show="userType ==2">
			<u-form :error-type="errorType" labelWidth="auto" :model="form2" ref="form2El" inputAlign="right"
				:label-style="labelStyle">
				<view class="u-m-t-12 u-m-b-12 bg-white u-p-l-24 u-p-r-24">
					<u-form-item label="真实姓名" prop="fullName">
						<u-input placeholder="请填写真实姓名" v-model="form2.fullName"></u-input>
					</u-form-item>
					<u-form-item label="手机号" prop="phone">
						<u-input type="number" placeholder="请输入手机号" v-model="form2.phone"></u-input>
					</u-form-item>
					<u-form-item label="提现方式" prop="cashType" v-show="false">
						<template #right>
							<u-button class="u-m-l-12" @click="form2.cashType = item.value"
								:type="item.value==form2.cashType?'success':'default'" size="mini"
								v-for="(item,index) in cashList" :key="index">{{item.name}}</u-button>
						</template>
					</u-form-item>
					<u-form-item label="企业名称" prop="businessName">
						<u-input v-model="form2.businessName" placeholder="请输入企业名称"></u-input>
					</u-form-item>
					<!-- <u-form-item label="持卡人姓名" prop="bank.cardName">
						<u-input v-model="form2.bank.cardName" placeholder="请输入持卡人姓名"></u-input>
					</u-form-item> -->
					<u-form-item label="企业联系人姓名" prop="linkName">
						<u-input v-model="form2.linkName" placeholder="请输入企业联系人姓名"></u-input>
					</u-form-item>

					<u-form-item label="企业联系人电话" prop="linkPhone">
						<u-input type="number" v-model="form2.linkPhone" placeholder="请输入企业联系人电话"></u-input>
					</u-form-item>
					<!-- <u-form-item label="银行卡类型" prop="bank.cardType">
						<template #right>
							<u-button class="u-m-l-12" @click="form2.bank.cardType = item.value"
								:type="item.value==form2.bank.cardType?'success':'default'" size="mini"
								v-for="(item,index) in cardTypeList" :key="index">{{item.name}}</u-button>
						</template>
					</u-form-item> -->
					<!-- <u-form-item label="身份证号" prop="idCard">
						<u-input type="idcard" v-model="form2.idCard" placeholder="请输入身份证号"></u-input>
					</u-form-item> -->

					<!-- <u-form-item label="银行" prop="bank.bankName">
						<u-input type="select" @click="showBank = true" v-model="form2.bank.bankName"
							placeholder="请选择银行"></u-input>
					</u-form-item> -->
					<!-- <u-form-item label="银行支行" prop="bank.branchName">
						<u-input type="select" @click="showBRcanch = true" v-model="form2.bank.branchName"
							placeholder="请选择支行"></u-input>
					</u-form-item> -->

					<!-- <u-form-item label="银行卡号" prop="bank.cardNo">
						<u-input v-model="form2.bank.cardNo" placeholder="请输入银行卡号"></u-input>
					</u-form-item> -->

				</view>

				<view class="u-m-t-12 u-m-b-12 bg-white u-p-l-24 u-p-r-24">
					<u-form-item class="uploadItem" :border-bottom="false" label-position="top" label="企业营业执照"
						prop="businessLicense">
						<u-upload index="businessLicense" :fileList="busineFileList" ref="businessLicenseEL"  :custom-btn="true"
							:auto-upload="false" :max-count='1' @on-list-change="onSuccess">
							<template #addBtn>
								<image mode="widthFix" class="addImg" src="@/static/images/my/busname.png"></image>
							</template>
						</u-upload>
					</u-form-item>

					<u-row gutter="16">
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label=" 身份证正面" prop="idCardFront">
								<u-upload index="idCardFront" :file-list="idCardFrontFileList" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image mode="widthFix" class="addImg" src="@/static/images/my/idCardFace.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="身份证反面" prop="idCardBack">
								<u-upload index="idCardBack" :file-list="idCardBackFileList" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image mode="widthFix" class="addImg" src="@/static/images/my/idCardBack.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
					</u-row>


					<!-- <u-row gutter="16" v-show="form2.bank.cardType==2">
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="银行卡正面"
								prop="bank.bankCardFront">
								<u-upload index="bankCardFront" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image style="opacity: .4;" mode="widthFix" class="addImg"
											src="@/static/images/my/bankface.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="银行卡背面" prop="bank.bankCardBack">
								<u-upload index="bankCardBack" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image style="opacity: .4;" mode="widthFix" class="addImg"
											src="@/static/images/my/banback.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
					</u-row> -->

				</view>
			</u-form>
		</view>

		<!-- 个人 -->
		<view v-show="userType ==3">
			<u-form :error-type="errorType" labelWidth="auto" :model="form3" ref="form3El" inputAlign="right"
				:label-style="labelStyle">
				<view class="u-m-t-12 u-m-b-12 bg-white u-p-l-24 u-p-r-24">
					<u-form-item label="真实姓名" prop="fullName">
						<u-input placeholder="请填写真实姓名" v-model="form3.fullName"></u-input>
					</u-form-item>
					<u-form-item label="手机号" prop="phone">
						<u-input type="number" placeholder="请输入手机号" v-model="form3.phone"></u-input>
					</u-form-item>
					<u-form-item label="提现方式" prop="cashType" v-show="false">
						<template #right>
							<u-button class="u-m-l-12" @click="form3.cashType = item.value"
								:type="item.value==form3.cashType?'success':'default'" size="mini"
								v-for="(item,index) in cashList" :key="index">{{item.name}}</u-button>
						</template>
					</u-form-item>
					<!-- <u-form-item label="银行卡类型" prop="bank.cardType">
						<template #right>
							<u-button class="u-m-l-12" @click="form3.bank.cardType = item.value"
								:type="item.value==form3.bank.cardType?'success':'default'" size="mini"
								v-for="(item,index) in cardTypeList" :key="index">{{item.name}}</u-button>
						</template>
					</u-form-item> -->
					<u-form-item label="身份证号" prop="idCard">
						<u-input type="idcard" v-model="form3.idCard" placeholder="请输入身份证号"></u-input>
					</u-form-item>

					<!-- <u-form-item label="银行" prop="bank.bankName">
						<u-input type="select" @click="showBank = true" v-model="form3.bank.bankName"
							placeholder="请选择银行"></u-input>
					</u-form-item> -->
					<!-- 	<u-form-item label="银行支行" prop="bank.branchName">
						<u-input type="select" @click="showBRcanch = true" v-model="form3.bank.branchName"
							placeholder="请选择支行"></u-input>
					</u-form-item> -->
					<!-- <u-form-item label="持卡人姓名" prop="bank.cardName">
						<u-input v-model="form3.bank.cardName" placeholder="请输入持卡人姓名"></u-input>
					</u-form-item> -->
					<!-- <u-form-item label="银行卡号" prop="bank.cardNo">
						<u-input v-model="form3.bank.cardNo" placeholder="请输入银行卡号"></u-input>
					</u-form-item> -->

				</view>

				<view class="u-m-t-12 u-m-b-12 bg-white u-p-l-24 u-p-r-24">


					<u-row gutter="16">
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="身份证正面" prop="idCardFront">
								<u-upload index="idCardFront" :file-list="idCardFrontFileList" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image mode="widthFix" class="addImg" src="@/static/images/my/idCardFace.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="身份证反面" prop="idCardBack">
								<u-upload index="idCardBack" :file-list="idCardBackFileList" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image mode="widthFix" class="addImg" src="@/static/images/my/idCardBack.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
					</u-row>


					<u-row gutter="16" v-show="form3.bank.cardType==2">
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="银行卡正面"
								prop="bank.bankCardFront">
								<u-upload index="bankCardFront" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image style="opacity: .4;" mode="widthFix" class="addImg"
											src="@/static/images/my/bankface.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
						<u-col span="6">
							<u-form-item class="uploadItem" label-position="top" label="银行卡背面" prop="bank.bankCardBack">
								<u-upload index="bankCardBack" :custom-btn="true" :auto-upload="false" :max-count='1'
									@on-list-change="onSuccess">
									<template #addBtn>
										<image style="opacity: .4;" mode="widthFix" class="addImg"
											src="@/static/images/my/banback.png">
										</image>
									</template>
								</u-upload>
							</u-form-item>
						</u-col>
					</u-row>

				</view>
			</u-form>
		</view>

		<view class="btnwrap">
			<u-button type="success" @click="submit">提交</u-button>
		</view>
	</view>

	<!-- 银行选择 -->
	<BankSelect @select="selectFn" v-model="showBank" type='1' />

	<!-- 银行支行选择 -->
	<BankSelect @select="selectFn" type='2' v-model:Fomr2="brcanchForm" v-model:modelValue="showBRcanch" />
</template>

<script setup lang="ts">
	import { reactive, ref } from "vue";
	import { onLoad, onReady } from '@dcloudio/uni-app';
	import userApi from '@/api/user'
	import BankSelect from '@/components/BankSelect/BankSelect.vue'
import { loginOut } from "../../../hooks/user";

	onLoad((res) => {
		userType.value = res.type
		if (res?.update) {
			update.value = true
			userApi.getAccountInfo().then(res => {
				delete res.data.banks
				delete res.data.bank
				switch (userType.value) {
					case '1':
						Object.assign(form1, res.data)
						break;

					case '2':
						Object.assign(form2, res.data)
						break;

					case '3':
						Object.assign(form3, res.data)
						break;
				}
				busineFileList.value = [{url:res.data.businessLicense}]
				idCardFrontFileList.value = [{url:res.data.idCardFront}]
				idCardBackFileList.value = [{url:res.data.idCardBack}]
				// idCardBack
			})
			// userApi.accinfo().then(res => {
			// 	delete res.data.banks
			// 	delete res.data.bank
			// 	switch (res.data.userType) {
			// 		case 1:
			// 			Object.assign(form1, res.data)
			// 			break;

			// 		case 2:
			// 			Object.assign(form2, res.data)
			// 			break;

			// 		case 3:
			// 			Object.assign(form3, res.data)
			// 			break;
			// 	}
			// })
		}
	})
	const errorType = ref(['message'])
	const update = ref(false)
	const userType = ref(null)
	const showBank = ref(false)
	const showBRcanch = ref(false)
	const businessLicenseEL = ref(null)
	const busineFileList = ref([])
	const idCardFrontFileList = ref([])
	const idCardBackFileList = ref([])
	let brcanchForm = reactive({
		pageNo: 1,
		pageSize: 100,
		branchName: '',
		bankCode: '',
	})

	onReady(() => {
		switch (userType.value) {
			case '1':
				form1El.value.setRules(rules1)
				break;

			case '2':
				form2El.value.setRules(rules2)
				break;
			case '3':
				form3El.value.setRules(rules3)
				break;
		}
	})


	const labelStyle = reactive({
		fontSize: '26rpx',
		color: "#303133"
	})

	const form1 = reactive({
		cashType: 1,//提现方式
		fullName: '',//真实姓名 && 法人
		phone: '',//手机号
		idCard: '',// 身份证号
		idCardFront: '',//身份证正面
		idCardBack: '',//身份证反面
		businessName: '',//企业名称
		businessLicense: '',//企业营业执照
		linkName: '',//企业联系人姓名
		linkPhone: '',//企业联系人电话
		businessId: '',//商户id

		bank: {
			cardType: 1,//银行卡类型
			cardName: '',//公司名称/持卡人姓名
			bankCode: '',//银行编号
			bankName: '',//银行名称
			branchCode: '',//支行编号
			branchName: '',//支行名称
			cardNo: '',//银行卡号
			bankCardFront: '',//银行卡正面
			bankCardBack: '',//银行卡背面
			defaultFlag: 1,//是否为结算卡
		}

	})

	const rules1 = reactive({
		fullName: {
			required: true,
			message: '请输入法人姓名',
			trigger: ['blur', 'change']
		},
		phone: [
			{
				required: true,
				message: '请输入法人手机号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value)
				},
				message: '请输入正确手机号',
				trigger: ['blur', 'change']
			}
		],
		idCard: [
			{
				required: true,
				message: '请输入身份证号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.idCard(value)
				},
				message: '请输入正确身份证号',
				trigger: ['blur', 'change']
			}
		],
		idCardFront: {
			required: true,
			message: '请上传正面照',
			trigger: ['blur', 'change']
		},
		idCardBack: {
			required: true,
			message: '请上传反面照',
			trigger: ['blur', 'change']
		},
		businessName: {
			required: true,
			message: '请输入企业名称',
			trigger: ['blur', 'change']
		},
		businessLicense: {
			required: true,
			message: '请上传营业执照',
			trigger: ['blur', 'change']
		},
		linkName: {
			required: true,
			message: '请输入企业联系人姓名',
			trigger: ['blur', 'change']
		},
		linkPhone: [
			{
				required: true,
				message: '请输入手机号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value)
				},
				message: '请输入正确手机号',
				trigger: ['blur', 'change']
			}
		],

		"bank.bankName": {
			required: true,
			message: '选择银行',
			trigger: ['blur', 'change']
		},
		"bank.branchName": {
			required: true,
			message: '请选择支行',
			trigger: ['blur', 'change']
		},
		"bank.cardName": {
			required: false,
			message: '请输入公司名称',
			trigger: ['blur', 'change']
		},
		"bank.cardNo": {
			required: true,
			message: '请输入卡号',
			trigger: ['blur', 'change']
		},
		"bank.bankCardFront": {
			validator: (rule, value, callback) => {
				if (form1.bank.cardType == 2) {
					return !uni.$u.test.isEmpty(form1.bank.bankCardFront)
				} else {
					return true
				}
			},
			message: '请上传银行卡正面照',
			trigger: ['blur', 'change']
		},
		"bank.bankCardBack": {
			validator: (rule, value, callback) => {
				if (form1.bank.cardType == 2) {
					return !uni.$u.test.isEmpty(form1.bank.bankCardBack)
				} else {
					return true
				}
			},
			message: '请上传银行卡背面照',
			trigger: ['blur', 'change']
		}
	})

	const form1El = ref(null)


	const form2El = ref(null)
	const form2 = reactive({
		cashType: 1,//提现方式
		fullName: '',//真实姓名 && 法人
		phone: '',//手机号
		idCard: '',// 身份证号
		idCardFront: '',//身份证正面
		idCardBack: '',//身份证反面
		businessName: '',//企业名称
		businessLicense: '',//企业营业执照
		linkName: '',//企业联系人姓名
		linkPhone: '',//企业联系人电话
		businessId: '',//商户id

		bank: {
			cardType: 2,//银行卡类型
			cardName: '',//公司名称/持卡人姓名
			bankCode: '',//银行编号
			bankName: '',//银行名称
			branchCode: '',//支行编号
			branchName: '',//支行名称
			cardNo: '',//银行卡号
			bankCardFront: '',//银行卡正面
			bankCardBack: '',//银行卡背面
			defaultFlag: 1,//是否为结算卡
		}

	})
	const rules2 = reactive({
		fullName: {
			required: true,
			message: '请输入法人姓名',
			trigger: ['blur', 'change']
		},
		phone: [
			{
				required: true,
				message: '请输入法人手机号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value)
				},
				message: '请输入正确手机号',
				trigger: ['blur', 'change']
			}
		],
		idCard: [
			{
				required: true,
				message: '请输入身份证号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.idCard(value)
				},
				message: '请输入正确身份证号',
				trigger: ['blur', 'change']
			}
		],
		idCardFront: {
			required: true,
			message: '请上传正面照',
			trigger: ['blur', 'change']
		},
		idCardBack: {
			required: true,
			message: '请上传反面照',
			trigger: ['blur', 'change']
		},
		businessName: {
			required: true,
			message: '请输入企业名称',
			trigger: ['blur', 'change']
		},
		businessLicense: {
			required: true,
			message: '请上传营业执照',
			trigger: ['blur', 'change']
		},
		linkName: {
			required: true,
			message: '请输入企业联系人姓名',
			trigger: ['blur', 'change']
		},
		linkPhone: [
			{
				required: true,
				message: '请输入手机号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value)
				},
				message: '请输入正确手机号',
				trigger: ['blur', 'change']
			}
		],

		"bank.bankName": {
			required: true,
			message: '选择银行',
			trigger: ['blur', 'change']
		},
		"bank.branchName": {
			required: true,
			message: '请选择支行',
			trigger: ['blur', 'change']
		},
		"bank.cardName": {
			required: false,
			message: '请输入持卡人姓名',
			trigger: ['blur', 'change']
		},
		"bank.cardNo": {
			required: true,
			message: '请输入卡号',
			trigger: ['blur', 'change']
		},
		"bank.bankCardFront": {
			validator: (rule, value, callback) => {
				if (form2.bank.cardType == 2) {
					return !uni.$u.test.isEmpty(form2.bank.bankCardFront)
				} else {
					return true
				}
			},
			message: '请上传银行卡正面照',
			trigger: ['blur', 'change']
		},
		"bank.bankCardBack": {
			validator: (rule, value, callback) => {
				if (form2.bank.cardType == 2) {
					return !uni.$u.test.isEmpty(form2.bank.bankCardBack)
				} else {
					return true
				}
			},
			message: '请上传银行卡背面照',
			trigger: ['blur', 'change']
		}

	})

	const form3El = ref(null)
	const form3 = reactive({
		cashType: 1,//提现方式
		fullName: '',//真实姓名 && 法人
		phone: '',//手机号
		idCard: '',// 身份证号
		idCardFront: '',//身份证正面
		idCardBack: '',//身份证反面

		bank: {
			cardType: 2,//银行卡类型
			cardName: '',//公司名称/持卡人姓名
			bankCode: '',//银行编号
			bankName: '',//银行名称
			branchCode: '',//支行编号
			branchName: '',//支行名称
			cardNo: '',//银行卡号
			bankCardFront: '',//银行卡正面
			bankCardBack: '',//银行卡背面
			defaultFlag: 1,//是否为结算卡
		}

	})

	const rules3 = reactive({
		fullName: {
			required: true,
			message: '请输入真实姓名',
			trigger: ['blur', 'change']
		},
		phone: [
			{
				required: true,
				message: '请输入手机号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value)
				},
				message: '请输入正确手机号',
				trigger: ['blur', 'change']
			}
		],
		idCard: [
			{
				required: true,
				message: '请输入身份证号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.idCard(value)
				},
				message: '请输入正确身份证号',
				trigger: ['blur', 'change']
			}
		],
		// idCardFront: {
		// 	required: true,
		// 	message: '请上传正面照',
		// 	trigger: ['blur', 'change']
		// },
		// idCardBack: {
		// 	required: true,
		// 	message: '请上传反面照',
		// 	trigger: ['blur', 'change']
		// },
		linkPhone: [
			{
				required: true,
				message: '请输入手机号',
				trigger: ['blur', 'change']
			},
			{
				validator: (rule, value, callback) => {
					return uni.$u.test.mobile(value)
				},
				message: '请输入正确手机号',
				trigger: ['blur', 'change']
			}
		],

		"bank.bankName": {
			required: true,
			message: '选择银行',
			trigger: ['blur', 'change']
		},
		"bank.branchName": {
			required: true,
			message: '请选择支行',
			trigger: ['blur', 'change']
		},
		"bank.cardName": {
			required: false,
			message: '请输入持卡人姓名',
			trigger: ['blur', 'change']
		},
		"bank.cardNo": {
			required: true,
			message: '请输入卡号',
			trigger: ['blur', 'change']
		},
		// "bank.bankCardFront": {
		// 	validator: (rule, value, callback) => {
		// 		if (form3.bank.cardType == 2) {
		// 			return !uni.$u.test.isEmpty(form3.bank.bankCardFront)
		// 		} else {
		// 			return true
		// 		}
		// 	},
		// 	message: '请上传银行卡正面照',
		// 	trigger: ['blur', 'change']
		// },
		// "bank.bankCardBack": {
		// 	validator: (rule, value, callback) => {
		// 		if (form3.bank.cardType == 2) {
		// 			return !uni.$u.test.isEmpty(form3.bank.bankCardBack)
		// 		} else {
		// 			return true
		// 		}
		// 	},
		// 	message: '请上传银行卡背面照',
		// 	trigger: ['blur', 'change']
		// }

	})

	const cashList = ref([
		{
			name: '自动提现',
			value: 1,

		},
		{
			name: '手动提现',
			value: 2,
		}
	])

	const cardTypeList = ref([
		{
			name: '对公账户',
			value: 1,
		},
		{
			name: '对私法人',
			value: 2,
		}
	])

	function submit() {
		let obj = {}
		//updateInfoAcc
		switch (userType.value) {
			case '1':
				form1El.value.validate((vali) => {
					if (!vali) return false
					obj = JSON.parse(JSON.stringify(form1))
				})
				break;

			case '2':
				form2El.value.validate((vali) => {
					if (!vali) return false
					obj = JSON.parse(JSON.stringify(form2))
				})
				break;

			case '3':
				form3El.value.validate((vali) => {
					if (!vali) return false
					obj = JSON.parse(JSON.stringify(form3))
				})
				break;
		}
		if (!uni.$u.test.isEmpty(obj)) {
			uni.showLoading({
				title: '加载中'
			})
			// if (update.value) {
			// 	userApi.updateInfoAcc(Object.assign(obj, { userType: userType.value })).then(res => {
			// 		uni.hideLoading()
			// 		uni.showToast({
			// 			title: res.msg
			// 		})
			// 	})
			// } else {
			// 	userApi.setAccountInfo(Object.assign(obj, { userType: userType.value })).then(res => {
			// 		uni.hideLoading()
			// 		uni.showToast({
			// 			title: res.msg
			// 		})
			// 	})
			// }

			userApi.setAccountInfo(Object.assign(obj, { userType: userType.value })).then(res => {
				uni.hideLoading()
				uni.showToast({
					title: res.msg
				})
			})
		}
	}

	// 图片上传
	async function onSuccess(lists, name) {
		if (lists.length > 0) {//上传
			switch (userType.value) {
				case '1':
					switch (name) {
						case 'businessLicense'://企业营业执照
							form1.businessLicense = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')

							break;
						case 'idCardFront': //身份证正面
							form1.idCardFront = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'idCardBack': //身份证背面
							form1.idCardBack = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'bankCardFront'://银行卡正面
							form1.bank.bankCardFront = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'bankCardBack'://银行卡背面
							form1.bank.bankCardBack = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
					}
					form1El.value.validate((vali) => { })
					break;
				case '2':
					switch (name) {
						case 'businessLicense'://企业营业执照
							form2.businessLicense = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')

							break;
						case 'idCardFront': //身份证正面
							form2.idCardFront = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'idCardBack': //身份证背面
							form2.idCardBack = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'bankCardFront'://银行卡正面
							form2.bank.bankCardFront = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'bankCardBack'://银行卡背面
							form2.bank.bankCardBack = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
					}
					form2El.value.validate((vali) => { })
					break;
				case '3':
					switch (name) {

						case 'idCardFront': //身份证正面
							form3.idCardFront = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'idCardBack': //身份证背面
							form3.idCardBack = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'bankCardFront'://银行卡正面
							form3.bank.bankCardFront = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
						case 'bankCardBack'://银行卡背面
							form3.bank.bankCardBack = uni.getFileSystemManager().readFileSync(lists[0].url, 'base64')
							break;
					}
					form3El.value.validate((vali) => { })
					break;
			}

		} else {//删除

		}
	}

	function selectFn(obj) {
		switch (userType.value) {
			case '1':
				Object.assign(form1.bank, obj)
				Object.assign(brcanchForm, obj)
				break;
			case '2':
				Object.assign(form2.bank, obj)
				Object.assign(brcanchForm, obj)
				break;
			case '3':
				Object.assign(form3.bank, obj)
				Object.assign(brcanchForm, obj)
				break;
		}
	}
</script>

<style lang="scss" scoped>
	.head {
		background-color: #35c877;
		padding: 30upx 28upx;
	}

	.addImg {
		display: block;
		width: 315upx;
		height: 202upx;
	}

	.btnwrap {
		margin-top: 52upx;
		padding-bottom: 150upx;
		padding-left: 24upx;
		padding-right: 24upx;
	}

	:deep(.uploadItem) {
		.u-form-item__message {
			text-align: left !important;
		}
	}
</style>

<style>
	page {
		background-color: #f6f6f6;
	}
</style>
